﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using PlanningGIS.Framework;
////using ESRI.ArcGIS.TOCControl;


namespace PlanningGIS.TocContextMenu.Button
{
    /// <summary>
    /// 作用：TOC右键菜单显示标注按钮类
    /// 作者：
    /// 编写日期:2008-08-01
    internal class ShowLabel : BaseCommand
    {
        IApplication m_Application = null;
        public ShowLabel()
        {
            base.m_caption = "标注";
            base.m_toolTip = base.Caption;
        }

        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;
        }
        public override void OnClick()
        {
            IGeoFeatureLayer pGeoLyr = (m_Application as IFramework).TOCControl.CustomProperty as IGeoFeatureLayer;
            pGeoLyr.DisplayAnnotation = !pGeoLyr.DisplayAnnotation;
            (m_Application as IFramework).MapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
        }

        public override bool Enabled
        {
            get
            {
                return ((m_Application as IFramework).IsMapCtrlactive && (m_Application as IFramework).TOCControl.CustomProperty is IGeoFeatureLayer) ? true : false;
            }
        }
        public override bool  Checked
        {

            get
            {
                if ((m_Application as IFramework).IsMapCtrlactive)
                {
                    if ((m_Application as IFramework).TOCControl.CustomProperty is IGeoFeatureLayer)
                    {
                        IGeoFeatureLayer pGeoLyr = (m_Application as IFramework).TOCControl.CustomProperty as IGeoFeatureLayer;
                        return pGeoLyr.DisplayAnnotation;
                    }
                }
                return false;
            }
        }
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.TocContextMenu.Res." + this.GetType().Name + ".ico";
                System.IO.Stream stream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (stream == null) return 0;

                return new Bitmap(stream).GetHbitmap().ToInt32();
            }
        }
    }
}
